﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] Array = { "Hjiang", "Hwang", "Wange", "Hwan", "Hcheng", "Hhoho" };

            //  然后我们对数组进行模拟分页  
            //以下读取第一页
            var sArray1 = GetIenumberable<String>(Array, r => r.StartsWith("H"), r => r, 1, 1);
            foreach (var s in sArray1)
            {
                Console.WriteLine(s);
            }
            //第二页
            var sArray2 = GetIenumberable<String>(Array, r => r.StartsWith("H"), r => r, 1, 2);
            foreach (var s in sArray2)
            {
                Console.WriteLine(s);
            }

            Console.Read();
        }         

        /// <summary>
        /// 数据分页方法Demo
        /// </summary>
        /// <typeparam name="T">typeparam</typeparam>
        /// <param name="List">实现IEnumerableparam</param>
        /// <param name="FunWhere">delegate检索条件param</param>
        /// <param name="FunOrder">delegate排序param</param>
        /// <param name="PageSize">每页显示数param</param>
        /// <param name="PageIndex">当前页码param</param>
        /// <returns>分页之后的数据</returns>
        static IEnumerable<T> GetIenumberable<T>(IEnumerable<T> List, Func<T, bool> FunWhere, Func<T, string> FunOrder, int PageSize, int PageIndex)
        {
            return List.Where(FunWhere).OrderByDescending(FunOrder).Select(t => t).Skip((PageIndex - 1) * PageSize).Take(PageSize);
        }



    }
}
